﻿@{
    Style.Require("NineSeas.SharePanel").AtHead();
    var url = Model.Url == null ? Request.Url.PathAndQuery : Model.Url;

    url = Uri.EscapeUriString(url);

    Func<string, string> ToAbsoluteUrl = s => {
        if (string.IsNullOrEmpty(s) 
            || HttpContext.Current == null
            || s.StartsWith("http:")
            || s.StartsWith("https:"))
            return s;

        if (s.StartsWith("/"))
            s = s.Insert(0, "~");
        if (!s.StartsWith("~/"))
            s = s.Insert(0, "~/");

        var u = HttpContext.Current.Request.Url;
        var port = u.Port != 80 ? (":" + u.Port) : String.Empty;

        return String.Format("{0}://{1}{2}{3}",
            u.Scheme, u.Host, port, VirtualPathUtility.ToAbsolute(s));
    };
}
@using (Script.Head())
{
    if (Model.ImageUrl != null) {
        <meta property="og:image" content="@ToAbsoluteUrl(Model.ImageUrl)"/>
        <link rel="image_src" href="@ToAbsoluteUrl(Model.ImageUrl)"/>
    }

    if (Model.Description != null)
    {
        <meta name="Description" content="@Model.Description"/>
        <meta property="og:description" content="@Model.Description"/>
    }
    if (Model.Type != null)
    {
        <meta property="og:type" content="@Model.Type"/>
    }
    else
    {
        <meta property="og:type" content="article"/>
    }
    if (Model.Keywords != null)
    {
        <meta name="Keywords" content="@Model.Keywords"/>
    }
}
<div id="share-panel">
    <a href="https://www.facebook.com/sharer/sharer.php?u=@url" class="share-button facebook-share">Facebook</a>
    <a href="http://www.twitter.com/share?url=@url" class="share-button twitter-share">Tweet</a>
    <a href="http://www.linkedin.com/shareArticle?mini=true&url=@url" class="share-button linkedin-share">Linked In</a>
    <a href="https://plus.google.com/share?url=@url" class="share-button gplus-share">Google +</a>
    <a href="http://pinterest.com/pin/create/button/?url=@url" class="share-button pinterest-share">Pinterest</a>
</div>
@using (Script.Foot())
{
<script type="text/javascript">
    (function () {
        $(".share-button").on("click", function () {
            var $this = $(this);
            window.open($this.attr("href"), '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');
            return false;
        });
    })()
</script>
}
